//
//  LBZhutiCourseCollectionViewCellTwo.m
//  V-Learn
//
//  Created by Apple on 2019/1/10.
//  Copyright © 2019 yxk. All rights reserved.
//

#import "LBZhutiCourseCollectionViewCellTwo.h"

@interface LBZhutiCourseCollectionViewCellTwo ()

@property (nonatomic, strong) UIImageView *leftIcon;

@property (nonatomic, strong) UIImageView *leftBgimageView;
@property (nonatomic, strong) UILabel *leftLab;
@end
@implementation LBZhutiCourseCollectionViewCellTwo
- (UIImageView *)leftBgimageView{
    if (!_leftBgimageView ) {
        _leftBgimageView = [[UIImageView alloc] init];
    }
    return _leftBgimageView;
}
- (UILabel *)leftLab{
    if (!_leftLab) {
        _leftLab = [UILabel labelWithText:@"主题课程第一季" andTextColor:rgb(51,51,51) andName:nil andFontSize:10];
    }
    return _leftLab;
}
- (UIImageView *)leftIcon{
    if (!_leftIcon) {
        _leftIcon = [[UIImageView alloc] init];
    }
    return _leftIcon;
}
- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        self = [[NSBundle mainBundle]loadNibNamed:@"LBZhutiCourseCollectionViewCellTwo" owner:self options:nil].lastObject;
        
    }
    return self;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    
    self.backgroundColor = [UIColor clearColor];
    
    //背景图
    [self.contentView addSubview:self.leftBgimageView];
    self.leftBgimageView.image = [UIImage imageNamed:@"tree_right"];
    [self.leftBgimageView makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.contentView);
        make.bottom.mas_equalTo(-25*kScaleFit);
        make.size.mas_equalTo(CGSizeMake(130*kScaleFit, 166*kScaleFit));
        
    }];
    
    //图
    [self.leftBgimageView addSubview:self.leftIcon];
    self.leftIcon.layer.cornerRadius = 5;
    self.leftIcon.layer.masksToBounds = NO;
    self.leftIcon.image = [UIImage imageNamed:@"wk_list_bgimg"];
    
    


 

//    UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:self.leftIcon.bounds byRoundingCorners:UIRectCornerBottomLeft | UIRectCornerBottomRight cornerRadii:CGSizeMake(0, 0)];
//    CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
//    maskLayer.frame = self.leftIcon.bounds;
//    maskLayer.path = maskPath.CGPath;
//    self.leftIcon.layer.mask = maskLayer;
    
//    [self.leftIcon makeConstraints:^(MASConstraintMaker *make) {
//
//        make.top.mas_equalTo(4);
//        make.height.mas_equalTo(51*kScaleFit);
//        make.left.mas_equalTo(5*kScaleFit);
//        make.right.mas_equalTo(-18*kScaleFit);
//    }];
//
//    CGRect rect = CGRectMake(0, 0, 105, 67);
//    CGSize radio = CGSizeMake(5, 5);//圆角尺寸
//    UIRectCorner corner = UIRectCornerTopLeft|UIRectCornerTopRight;//这只圆角位置
//    UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:rect byRoundingCorners:corner cornerRadii:radio];
//    CAShapeLayer *masklayer = [[CAShapeLayer alloc]init];//创建shapelayer
//    masklayer.frame = self.leftIcon.bounds;
//    masklayer.path = path.CGPath;//设置路径
//    self.leftIcon.layer.mask = masklayer;
    CGRect rect = CGRectMake(0, 0, 109, 56);
    CGSize radio = CGSizeMake(5, 5);//圆角尺寸
    UIRectCorner corner = UIRectCornerTopLeft|UIRectCornerTopRight;//这只圆角位置
    UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:rect byRoundingCorners:corner cornerRadii:radio];
    CAShapeLayer *masklayer = [[CAShapeLayer alloc]init];//创建shapelayer
    masklayer.frame = self.leftIcon.bounds;
    masklayer.path = path.CGPath;//设置路径
    
    self.leftIcon.layer.mask = masklayer;
    self.leftIcon.frame = CGRectMake(5*kScaleFit, 3*kScaleFit, 109*kScaleFit, 56*kScaleFit);
    
//    UIView *smallView = [UIView new];
//
//    smallView.backgroundColor = [UIColor whiteColor];
//
//
////        CGRect rect2 = CGRectMake(0, 0, 105, 21);
////        CGSize radio2 = CGSizeMake(5, 5);//圆角尺寸
////        UIRectCorner corner2 = UIRectCornerBottomLeft|UIRectCornerBottomRight;//这只圆角位置
////        UIBezierPath *path2 = [UIBezierPath bezierPathWithRoundedRect:rect2 byRoundingCorners:corner2 cornerRadii:radio2];
////        CAShapeLayer *masklayer2 = [[CAShapeLayer alloc]init];//创建shapelayer
////        masklayer.frame = smallView.bounds;
////        masklayer.path = path2.CGPath;//设置路径
////        smallView.layer.mask = masklayer2;
//    [self.leftBgimageView addSubview:smallView];
//    [smallView makeConstraints:^(MASConstraintMaker *make) {
//        make.top.mas_equalTo(self.leftIcon.mas_bottom);
//        make.left.mas_equalTo(5*kScaleFit);
//        make.right.mas_equalTo(-18*kScaleFit);
//        make.height.mas_equalTo(22);
//    }];
//
//
//    // 标题
//    [smallView addSubview:self.leftLab];
//    [self.leftLab makeConstraints:^(MASConstraintMaker *make) {
////        make.bottom.mas_equalTo(0);
//        make.centerX.mas_equalTo(self.leftIcon);
//        make.centerY.mas_equalTo(smallView);
//    }];
    
    UIView *smallView = [UIView new];
    
    smallView.backgroundColor = [UIColor whiteColor];
    [self.leftBgimageView addSubview:smallView];
    
    smallView.frame = CGRectMake(5*kScaleFit, 56*kScaleFit, 109*kScaleFit, 21*kScaleFit);
    UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:smallView.bounds byRoundingCorners:UIRectCornerBottomLeft | UIRectCornerBottomRight cornerRadii:CGSizeMake(5, 5)];
    
    CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
    
    maskLayer.frame = smallView.bounds;
    
    maskLayer.path = maskPath.CGPath;
    
    smallView.layer.mask = maskLayer;
    
    
    //    self.leftLab.frame = CGRectMake(0, 5, CGRectGetMaxX(smallView.frame), 22);
    self.leftLab.textAlignment = NSTextAlignmentCenter;
    [smallView addSubview:self.leftLab];
    [self.leftLab makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.leftIcon);
        make.centerY.mas_equalTo(smallView);
    }];

}

- (void)setModel:(LBCourseOutputDTOListModel *)model{
    _model = model;
    
    NSString *urlString = [NSString stringWithFormat:@"%@%@",Public_URL,model.courseImage];
    [self.leftIcon sd_setImageWithURL:[NSURL URLWithString:urlString] placeholderImage:[UIImage imageNamed:@"wk_list_bgimg"]];
    self.leftLab.text = model.courseName;
}
@end
